import request from '@/utils/request'

// 教师成绩管理API
export const gradeTeacherApi = {
  // 获取教师成绩列表
  getTeacherGrades: (params) => {
    return request({
      url: '/grades/teacher/query',
      method: 'post',
      data: params
    })
  },

  // 保存成绩
  saveGrade: (data) => {
    return request({
      url: '/grades/save',
      method: 'post',
      data
    })
  },

  // 修改成绩
  updateGrade: (data) => {
    return request({
      url: '/grades/update',
      method: 'put',
      data
    })
  },

  // 送审成绩
  submitGradeForReview: (gradeId) => {
    return request({
      url: `/grades/submit/${gradeId}`,
      method: 'post'
    })
  },

  // 批量送审成绩
  batchSubmitGradeForReview: (gradeIds) => {
    return request({
      url: '/grades/batch-submit',
      method: 'post',
      data: gradeIds
    })
  },

  // 获取教师负责的学生列表
  getTeacherStudents: (params) => {
    return request({
      url: '/grades/teacher/students',
      method: 'post',
      data: params
    })
  },

  // 获取教师负责的课程列表
  getTeacherCourses: (params) => {
    return request({
      url: '/grades/teacher/courses',
      method: 'post',
      data: params
    })
  }
}

// 学生成绩查看API
export const gradeStudentApi = {
  // 获取学生成绩列表
  getStudentGrades: (params) => {
    return request({
      url: '/grades/student/query',
      method: 'post',
      data: params
    })
  }
}

// 教务员成绩审核API
export const gradeAdminApi = {
  // 获取待审核成绩列表
  getPendingGrades: (params) => {
    return request({
      url: '/grades/review/pending/query',
      method: 'post',
      data: params
    })
  },

  // 审核成绩（单个）
  reviewGrade: (params) => {
    return request({
      url: '/grades/review/single',
      method: 'post',
      data: params
    })
  },

  // 批量审核成绩
  batchReviewGrade: (params) => {
    return request({
      url: '/grades/review/batch',
      method: 'post',
      data: params
    })
  },

  // 获取成绩详情
  getGradeDetail: (gradeId) => {
    return request({
      url: `/grades/detail/${gradeId}`,
      method: 'get'
    })
  },

  // 获取审核统计
  getReviewStatistics: () => {
    return request({
      url: '/grades/review/statistics',
      method: 'get'
    })
  }
}

// 管理员成绩统计API
export const gradeStatisticsApi = {
  // 获取所有学生成绩列表
  getAllGrades: (params) => {
    return request({
      url: '/grades/admin/all/query',
      method: 'post',
      data: params
    })
  },

  // 获取成绩统计数据
  getGradeStatistics: (params) => {
    return request({
      url: '/grades/admin/statistics/query',
      method: 'post',
      data: params
    })
  },

  // 获取成绩等级分布
  getGradeDistribution: (params) => {
    return request({
      url: '/grades/admin/grade-distribution/query',
      method: 'post',
      data: params
    })
  },

  // 获取平均分趋势
  getAverageScoreTrend: () => {
    return request({
      url: '/grades/admin/average-score-trend',
      method: 'get'
    })
  },

  // 获取各课程平均分排行
  getCourseAverageScores: (params) => {
    return request({
      url: '/grades/admin/course-average-scores/query',
      method: 'post',
      data: params
    })
  },

  // 获取各专业/学院平均分统计
  getDepartmentAverageScores: (params) => {
    return request({
      url: '/grades/admin/department-average-scores/query',
      method: 'post',
      data: params
    })
  }
}

// 通用API
export const gradeApi = {
  // 根据ID获取成绩详情
  getGradeById(gradeId) {
    return request({
      url: `/grades/${gradeId}`,
      method: 'get'
    })
  },

  // 根据学生和课程获取成绩
  getGradeByStudentAndCourse(studentId, courseId) {
    return request({
      url: '/grades/student-course/query',
      method: 'post',
      data: { studentId, courseId }
    })
  }
}

// 导出便捷函数
export const {
  getAllGrades,
  getGradeStatistics,
  getGradeDistribution,
  getAverageScoreTrend,
  getCourseAverageScores,
  getDepartmentAverageScores
} = gradeStatisticsApi

export default {
  ...gradeTeacherApi,
  ...gradeStudentApi,
  ...gradeAdminApi,
  ...gradeStatisticsApi,
  ...gradeApi
} 